package com.zjun.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.zjun.handler.CustomIdGenerator;
import com.zjun.handler.MyMetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * MyBatisPlus配置文件
 */
@Configuration
public class MybatisPlusAutoConfiguration {

    /**
     * 分页插件
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    /**
     * 元数据填充
     * @return
     */
    @Bean
    public MyMetaObjectHandler myMetaObjectHandler(){return new MyMetaObjectHandler();}

    /**
     * 雪花算法生成
     * @return
     */
    @Bean
    @Primary
    public IdentifierGenerator identifierGenerator(){return new CustomIdGenerator();}
}
